<?php
	class Default_Model_Category extends Zendvn_Model_Nested
	{
		protected $_db;
		
		public function __construct()
		{
			$this->_db = Zend_Registry::get('db');
		}
        
        public function listCategory($name)
		{
            $data = array(
                'id',
                'name',
                'parents',
                'url',
            );
			$sql = $this->_db->select()
							 ->from($name)
                             ->where('status = 1')
                             ->where('level <> 0')
							 ->order('lft ASC');
			$result = $this->_db->fetchAll($sql);
			return $result;
		}
        
        public function getName($id, $name)
        {
            $sql = $this->_db->select()
                            ->from($name, array('name'))
                            ->where('id = ?', $id)
                            ->where('status = 1');
            $result = $this->_db->fetchOne($sql);
            return $result;
        }
        
        public function getChild($id, $name)
        {
            $sql = $this->_db->select()
                            ->from($name, array('id','name','url'))
                            ->where('parents = ?', $id)
                            ->where('status = 1');
            $result = $this->_db->fetchAll($sql);
            return $result;
        }
    }
